//#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include "itch41reader.h"
#include "defaultdataclient.h"

using namespace openitch;

int main(int argc, char * argv[])
{
	if (2!=argc)
	{
		printf("Usage: ./itch41 filename\n");
		return 0;
	}
	char const * filename = argv[1];
	int fd = open(filename,O_RDONLY);
	if (fd<0)
	{
		printf("Couldn't open '%s'!\n",filename);
		return 0;
	}
	printf("Starting\n");
	defaultdataclient client;
	itch41reader reader(&client,0xffff);
	while (1)
	{
		char msgheader = reader.processpacket(fd);
		if (!msgheader) break;
	}
	long elapsed = reader.elapsed();
	long msgcount = reader.getmsgcount();
	printf("%ld messages processed in %d seconds\n",msgcount,elapsed/onebillion);
	double nanospermsg = elapsed / (double)msgcount;
	printf("Avg nanos / msg %f\n",nanospermsg);
}
